﻿using System;
using System.Collections.Generic;
using System.Text;

namespace Noris.Schedule.Support.Data
{
	// Struktura, která dovolí uschovat dvě hodnoty Int32, a používat tuto dvojici jako klíč v Dictionary, Hashtable atd.
	/// <summary>
	/// Struktura, která dovolí uschovat dvě hodnoty Int32, a používat tuto dvojici jako klíč v Dictionary, Hashtable atd.
	/// Implementuje optimální variantu GetHashCode() a Equals().
	/// </summary>
	public struct TwoInt32
	{
		#region KONSTRUKCE
		/// <summary>
		/// Konstruktor
		/// </summary>
		/// <param name="key"></param>
		/// <param name="subKey"></param>
		public TwoInt32(int key, int subKey)
		{
			this._Key = key;
			this._SubKey = subKey;
		}
		/// <summary>
		/// Klíč
		/// </summary>
		public int Key { get { return _Key; } }
		private int _Key;
		/// <summary>
		/// Subklíč
		/// </summary>
		public int SubKey { get { return _SubKey; } }
		private int _SubKey;
		#endregion
		#region OVERRIDES
		/// <summary>
		/// Porovná dva objekty co do shodnosti obsahu
		/// </summary>
		/// <param name="obj"></param>
		/// <returns></returns>
		public override bool Equals(object obj)
		{
			if (obj is TwoInt32)
			{
				TwoInt32 other = (TwoInt32)obj;
				return this._Key == other._Key && this._SubKey == other._SubKey;
			}
			return false;
		}
		/// <summary>
		/// Vrátí Hashcode
		/// </summary>
		/// <returns></returns>
		public override int GetHashCode()
		{
			return this._Key ^ this._SubKey;
		}
		/// <summary>
		/// Vizualizace
		/// </summary>
		/// <returns></returns>
		public override string ToString()
		{
			return "{" + this._Key.ToString() + ":" + this._SubKey.ToString() + "}";
		}
		#endregion
	}
}
